//
//  KuangJiShouYiViewController.m
//  DBAChain
//
//  Created by Evan on 2018/9/8.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "KuangJiShouYiViewController.h"
#import <Masonry.h>
#import "CommonData.h"
#import "SuanMaTopView.h"
#import "ShouYiJiLuTableViewCell.h"
#import "taskOverviewService.h"

@interface KuangJiShouYiViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)    UITableView *tableView;

@property (nonatomic,strong)    SuanMaTopView* viewTop;
@property (nonatomic,strong)    NSArray<dataUserMinerProfitList*> *  modelList;

@end

@implementation KuangJiShouYiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"算码收益记录";
    [self viewTop];
    [self tableView];
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self setBlackStatus:YES];
    self.hidesBottomBarWhenPushed = NO;
    if (self.tabBarController.tabBar.hidden == NO) {
        self.tabBarController.tabBar.hidden = YES;
    }
}


///topview  标题
-(SuanMaTopView*)viewTop{
    if (!_viewTop) {
        _viewTop = [[SuanMaTopView alloc]init];
        [self.view addSubview:_viewTop];
        [_viewTop mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.view.mas_left).offset(0);
            make.top.mas_equalTo(self.view.mas_top).offset(60);
            make.right.mas_equalTo(self.view.mas_right).offset(0);
            make.height.offset(40);
        }];
    }
    return _viewTop;
}

#pragma mark - 加载数据

- (void)loadData{
    [DKProgressHUD showLoading];
    [taskOverviewService getUserMinerProfit:nil success:^(dataUserMinerProfit *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.modelList = [response.data copy];
            [self.tableView reloadData];
        }
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}



#pragma mark - tableivew


-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.view).offset(0);;
            make.right.mas_equalTo(self.view).offset(0);
            make.top.mas_equalTo(self.viewTop.mas_bottom).offset(0);
            make.bottom.mas_equalTo(self.view).offset(0);
        }];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        //定义显示默认cell的横线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor clearColor];
    }
    return _tableView;
}

#pragma mark - UITableViewDelegate

//定义每一个section有多少row
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

//定义有多少section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.modelList count];
}

//定义CellRow的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

//定义section的Footer的view视图
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = COLOR_Background;
    return view;
}

//定义section的Footer的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}


//定义section的header的view视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = COLOR_Background;
    return view;
}

//定义section的header的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}

//主体cell的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ShouYiJiLuTableViewCell *cell = [ShouYiJiLuTableViewCell cellWithTableView:tableView IndexPath:indexPath];
    dataUserMinerProfitList *mm = [self.modelList objectAtIndex:indexPath.section];
    dataUserMinerProfitList *mmm = [dataUserMinerProfitList mj_objectWithKeyValues:mm];
    cell.labelName.text = mmm.name;
    cell.labelNo.text = mmm.number;
    cell.labelYE.text = mmm.profit;
    cell.labelTime.text = mmm.runtime;
    return cell;
}



@end
